package com.Servlet;

import com.Service.Impl.UserServiceImpl;
import com.Service.UserService;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 冷俊杰
 * @Description: 登录测试
 * @DateTime: 2022/6/2 14:57
 **/
@WebServlet("/AddUserServlet")
public class AddUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserService service = new UserServiceImpl();
        String username = req.getParameter("username1");
        String password = req.getParameter("password1");
        String phone = req.getParameter("phone");

        int i = service.insertUser(new User(phone, username, password));
        if (i > 0) {
            System.out.printf("成功");
            req.getRequestDispatcher("/register.jsp").forward(req, resp);
        } else {
            System.out.printf("失败");
            req.getRequestDispatcher("/register.jsp").forward(req, resp);
        }
    }
}
